package com.hjwoo.app.views;

import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.android.gms.common.api.GoogleApiClient;
import com.hjwoo.app.R;
import com.hjwoo.app.baseviews.BaseAppCompatActivity;
import com.hjwoo.app.common.AppManager;
import com.hjwoo.app.net.RequestListener;
import com.hjwoo.app.net.RequestTag;
import com.hjwoo.app.ui.CenterAlertBenefitDialog;
import com.hjwoo.app.ui.CenterAlertDialog;
import com.hjwoo.app.ui.CenterAlertDialogNoTitle;
import com.hjwoo.app.utils.Utils;

/**
 * Created by Administrator on 2016/5/6 0006.
 * //评房成功
 */
public class EvaluateSuccessActivity extends BaseAppCompatActivity implements RequestListener {

    //获取Activity实例
    public static EvaluateSuccessActivity instance;
    String jsonStr;
    String message;
    private TextView scope, money, title, house_title;
    private Button now, cancle, btnBack,tv_benefit,remove_dialog;
    private String unitPrice, loanAmount, minLoanAmount, serialNumber;
    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    private CenterAlertDialogNoTitle centerAlertDialogNoTitle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_evalustesuccess);
        instance = this;
        Utils.initTitle("房产信息", this, true);
        centerAlertDialogNoTitle = new CenterAlertDialogNoTitle(
                EvaluateSuccessActivity.this, R.style.Theme_Popdialog, "", "您确认放弃报单么?");
        if (getIntent() != null) {
            unitPrice = getIntent().getStringExtra("unitPrice");
            loanAmount = getIntent().getStringExtra("loanAmount");
            minLoanAmount = getIntent().getStringExtra("minLoanAmount");
            serialNumber = getIntent().getStringExtra("serialNumber");
        }
        init();
    }

    private void init() {
        money = (TextView) findViewById(R.id.evaluste_money_tv);//估值单价
        scope = (TextView) findViewById(R.id.evaluste_scope_tv);//估值总价
        now = (Button) findViewById(R.id.evaluste_now_btn);//立即报单
        cancle = (Button) findViewById(R.id.evaluste_cancle_btn);//返回首页
        title = (TextView) findViewById(R.id.evaluatesuccess_title_txt);
        title.setTextColor(getResources().getColor(R.color.home_boder_color));
        findViewById(R.id.evaluatesuccess_title_line).setBackgroundColor(getResources().getColor(R.color.home_boder_color));
        house_title = (TextView) findViewById(R.id.houseinformation_title_txt);
        house_title.setTextColor(getResources().getColor(R.color.home_boder_color));
        findViewById(R.id.houseinformation_title_line).setBackgroundColor(getResources().getColor(R.color.home_boder_color));
        btnBack = (Button) findViewById(R.id.btnBack);
        tv_benefit = (Button) findViewById(R.id.tv_benefit);
        money.setText(unitPrice);
        scope.setText(minLoanAmount + "~" + loanAmount);
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AppManager.getAppManager().finishAllActivity();
            }
        });
        now.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(EvaluateSuccessActivity.this, ImmediatelyActivity.class);
                intent.putExtra("serialNumber", serialNumber);
                startActivity(intent);
            }
        });
        //监听返回键
      btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                centerAlertDialogNoTitle.show();
            }
        });

       //报单的好处
        tv_benefit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new CenterAlertBenefitDialog(EvaluateSuccessActivity.this, R.style.Theme_Popdialog, "", "").show();
            }
        });
    }


    //监听手机返回键


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK ){
            centerAlertDialogNoTitle.show();
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void requestSuccess(String tag, String message) {
        if (tag.equals(RequestTag.APPCREATE)) {
            this.message = message;
        }
    }

    @Override
    public void requestError(String message) {

    }

    @Override
    protected void onDestroy() {
        try{
            centerAlertDialogNoTitle.dismiss();
        }catch (Exception e) {
            // TODO: handle exception
        }
        super.onDestroy();
    }
}
